package com.mm.dss.demo;

import android.Manifest;
import android.app.Activity;
import android.content.Intent;
import android.os.Build;
import android.os.Process;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.RadioButton;
import android.widget.TextView;

import com.fastaccess.permission.base.PermissionHelper;
import com.mm.dss.demo.base.BaseActivity;

import butterknife.BindInt;
import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.OnClick;

public class ZhuMainActivity extends BaseActivity {
    TextView txt_title;
    RadioButton tongzhi;//
    TextView txtright;
    private PermissionHelper mPermissionHelper;
    public static Activity activity;
    private final static String[] MULTI_PERMISSIONS = new String[]{
            //需要动态申请的权限
            Manifest.permission.WRITE_EXTERNAL_STORAGE,
            Manifest.permission.READ_EXTERNAL_STORAGE,
            Manifest.permission.CAMERA,
            Manifest.permission.ACCESS_NOTIFICATION_POLICY,  //获取通知栏权限
            Manifest.permission.ACCESS_COARSE_LOCATION,
            Manifest.permission.ACCESS_FINE_LOCATION,
            Manifest.permission.READ_PHONE_STATE
    };

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_zhu_main);
        activity = this;
        initview();
        initdata();
    }

    private void initview() {
        txt_title = (TextView) findViewById(R.id.txt_title);
        tongzhi = (RadioButton) findViewById(R.id.tongzhi);
        txtright = (TextView) findViewById(R.id.right);
        txtright.setVisibility(View.VISIBLE);
        txt_title.setText("首页");
        /*权限动态申请*/
        mPermissionHelper = PermissionHelper.getInstance(this);
        mPermissionHelper.request(MULTI_PERMISSIONS);
    }

    private void initdata() {
    }


    public void onclick(View view) {
        switch (view.getId()) {
            case R.id.right:
                //个人中心
                startActivity(new Intent(ZhuMainActivity.this, MineActivity.class));
                break;
            case R.id.yjxx://预警信息
                startActivity(new Intent(ZhuMainActivity.this, YjxxActivity.class));
                break;
            case R.id.xxpx://学习培训
                startActivity(new Intent(ZhuMainActivity.this, XxpxActivity.class));
                break;
            case R.id.sjcx://监测数据查询
                startActivity(new Intent(ZhuMainActivity.this, SJCXZLActivity.class));
                break;
            case R.id.tongzhi://通知公告
                startActivity(new Intent(ZhuMainActivity.this, TongZhiActivity.class));
                break;
            case R.id.qfqc://群防群测
                startActivity(new Intent(ZhuMainActivity.this, QfqcActivity.class));
                break;
            case R.id.xxcj://信息采集
                startActivity(new Intent(ZhuMainActivity.this, XxCjlistActivity.class));
                break;
            case R.id.dtyl://地图预览
                startActivity(new Intent(ZhuMainActivity.this, MapActivity.class));
                break;
            case R.id.xxcx://信息查询隐患点
                startActivity(new Intent(ZhuMainActivity.this, XxcxActivity.class));
                break;
            case R.id.spjk://视频监控
                startActivity(new Intent(ZhuMainActivity.this, LoginActivity.class));
                break;
        }
    }

    long lastBack = 0;

    @Override
    public void onBackPressed() {
        long currentBack = System.currentTimeMillis();
        if (currentBack - lastBack > 2000) {
            lastBack = currentBack;
            toast("再按一次返回键退出程序");
        } else {
            exitApp();
        }
    }

    private void exitApp() {
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
            finishAndRemoveTask();
        } else {
            finish();
            SLoginActivity.activity.finish();
        }
        System.exit(0);
        Process.killProcess(Process.myPid());
    }
}
